
const db = require( "../models" );
const logger = require( "../utils/utils.logger" );
const tools = require( "../utils/utils.tools" );
const DAO = require( "../dao/DAO" );
const speciality = db.speciality;

exports.getAllList = function ( pm, cb ) {
    //获取资历

    DAO.list( speciality, pm, list => {
        cb( list )
    } )
}
// Retrieve all comment from the database.
exports.list = ( req, res ) => {
    const pm = req.body;
    pm.params.type = 2
    DAO.list( speciality, pm, list => {
        //logger.debug(`${req.method} ${req.baseUrl + req.path} *** 参数：${JSON.stringify(pm)}; 响应：${JSON.stringify(list)}`);
  
        res.sendResult( list )
    } )
};

exports.create = ( req, res ) => {
    const pm = req.body;
    // 请求验证
    if ( !pm.name ) return res.sendResult( {
        data: '',
        code: 605,
        message: "名称不能为空"
    } )
    
    const createData = {
        skilled: pm.skilled,
        show: pm.show,
        index: pm.index,
        type: pm.type,
        name: pm.name
    };
     DAO.create( speciality, createData, data => {
         //logger.info(`${req.method} ${req.baseUrl + req.path} *** 参数：${JSON.stringify(pm)}; 响应：${JSON.stringify(data)}`);
         res.sendResult( data )
     } )
   
};


exports.update = ( req, res ) => {
    const pm = req.body;
    // 请求验证
    if ( !pm.id ) return res.sendResult( {
        data: '',
        code: 605,
        message: "ID不能为空！"
    } )
  
    DAO.update( speciality, pm, {
        id: pm.id
    }, data => {
        res.sendResult( data )
    } )

};
exports.delete = ( req, res ) => {
    const pm = req.body;
    // 请求验证
    if ( !pm.id ) return res.sendResult( {
        data: '',
        code: 605,
        message: "ID不能为空！"
    } )
    DAO.delete( speciality, {
        id: pm.id
    }, data => {
        res.sendResult( data )
    } )
};
